
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="../../../taglib.jsp" %>
<html>
<head>
    <title>千寻</title>

</head>
<body id="page">

<form class="layui-form">
    <div style="margin-left: 20px;">

    </div>
    <table class="layui-table">
        <thead>
        <tr>
            <th>用户名</th>
            <th>手机号码</th>
            <th>注册时间</th>
            <th>修改时间</th>
            <th>角色</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="item">
            <tr class="gradeX">
                <td style="text-align: center;">${item.userName}</td>
                <td style="text-align: center;">${item.mobile}</td>
                <td style="text-align: center;">${item.createTime}</td>
                <td style="text-align: center;">
                    <c:choose>
                        <c:when test="${item.updateTime!=null && item.updateTime!=''}">
                            ${item.updateTime}
                        </c:when>
                        <c:otherwise>暂无修改</c:otherwise>
                    </c:choose>
                </td>
                <td style="text-align: center;">${item.description}</td>
                <td style="text-align: center;">
                    <a href="javascript:void (0);" class="layui-btn layui-btn-mini">查看</a>
                    <a href="javascript:void (0);" onclick="changeRole('${item.id}');" class="layui-btn layui-btn-mini">更改角色</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div id="demo1"></div>
</form>
<script type="text/javascript">
    layui.use(['laypage', 'layer'], function() {
        var laypage = layui.laypage
                , layer = layui.layer;
        //调用分页
        laypage({
            cont: 'demo1'
            ,pages: Math.ceil(${pageInfo.total}) //得到总页数
            ,curr : ${pageInfo.pageNo}
            ,skin : '#009688'
            ,jump: function(obj,first){
                var curr = '${pageInfo.pageNo}';
                if(first == true){

                }else{
                    curr = obj.curr;
                    $('#page').load('${path}/user/userList.do?pageNo='+curr);
                }
            }
        });
    });

    function changeRole(id) {
        layer.open({
            type: 2,
            title: '修改用户角色',
            fix: false,
            maxmin: true,
            shadeClose: false,
            area: ['1000px', '600px'],
            btn: ['保存', '关闭'],
            content: '${path}/user/showEditRolePage.do?userId='+id+'&roleId='+0,
            success: function (layero,index) {
                var body = layer.getChildFrame('body', index);
                iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();

            },btn1: function (index) {
                var obj = iframeWin.submitIframe();
                $.ajax({
                    url:'${path}/user/editUserRole.do',
                    data:{
                        roleId : obj.roleId,
                        userId : obj.userId
                    },
                    type:'post',
                    dataType:'json',
                    success:function (data) {
                        if(data.result=='success'){
                            layer.alert("修改成功!");
                            window.location.href='${path}/user/userList.do';
                        }else if(data.result=='failed'){
                            layer.alert("权限不足!");
                            layer.close(index);
                        }else{
                            layer.alert("添加失败!");
                            layer.close(index);
                        }
                    },
                    error:function () {
                        layer.alert("请求发生错误!");
                    }

                });
            },
            btn2: function() {
                layer.close();
            },

        });
    }
</script>
</body>
</html>
